package com.edais.service.imp;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.edais.dao.UserChannelPointDao;
import com.edais.domain.ChannelWelfareParameters;
import com.edais.domain.UserChannelPoint;
import com.edais.service.WelfareService;

/**
 * 专享加息福利发放
 * @author zhouyj
 *
 */
@Service("vipInterestWelfareServiceImpl")

public class VipInterestWelfareServiceImpl implements WelfareService {

	private static final Log logger = LogFactory.getLog(VipInterestWelfareServiceImpl.class);
	
	@Autowired 
	private UserChannelPointDao userChannelPointDao;

	@Override
	public Map<String,Object> addWelfare(ChannelWelfareParameters channelWelfareParameters,Map<String,Object> paramsMap) throws Exception {
		logger.info("******发放专享加息福利，福利参数id："+channelWelfareParameters.getId()+",发放用户"+paramsMap.get("userId")+"********");
		// 用户渠道等级积分表写入
		UserChannelPoint userChannelPoint = new UserChannelPoint();
		userChannelPoint.setUserId(paramsMap.get("userId").toString());
		userChannelPoint.setUserChannel(paramsMap.get("channelId").toString());
		userChannelPoint.setCurrentFloatRateChannel(channelWelfareParameters.getCurrentFloatRate().toString());
		userChannelPoint.setFixFloatRateChannel(channelWelfareParameters.getFixFloatRate().toString());
		SimpleDateFormat hmsFormat = new SimpleDateFormat("yyyyMMdd");
		Date date = new Date();
		String nowYmd = hmsFormat.format(date);
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.DATE,channelWelfareParameters.getExpires()-1);
		userChannelPoint.setStartTime(nowYmd);
		userChannelPoint.setEndTime(hmsFormat.format(cal.getTime()));
		userChannelPointDao.addChannelPoint(userChannelPoint);
		return null;
	}
	


}
